import {createStore,applyMiddleware} from 'redux';
import thunk from 'redux-thunk';
import rootReducer from '../reducer/index';
import createLogger from 'redux-logger';
import delay from '../middleware/delayMiddleware'
import http from '../middleware/httpMiddleware'
import { composeWithDevTools } from 'redux-devtools-extension';

const enhancer = composeWithDevTools({

})(applyMiddleware(thunk,createLogger,delay,http));
const createStoreMilleware = enhancer(createStore);

export default function (initailState) {
    const store = createStoreMilleware(rootReducer,initailState);

    if (module.hot) {
        module.hot.accept(() => {
            const nextRootReducer = require('../reducer/index').default;
            store.replaceReducer(nextRootReducer);
        });
    }
    return store;
}